UNPKG

medusa-plugin-product-reviews-kvy

Version:

Plugins Product Reviews for Medusa ecommerce server.

47 lines (46 loc) 2.11 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.GET = GET; var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); function GET(_x, _x2) { return _GET.apply(this, arguments); } function _GET() { _GET = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(req, res) { var id, _ref, _ref$page, page, _ref$limit, limit, _ref$approved, approved, productReviewService, _yield$productReviewS, reviews, total; return _regenerator["default"].wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: _context.prev = 0; id = req.params.id; _ref = req.query, _ref$page = _ref.page, page = _ref$page === void 0 ? 1 : _ref$page, _ref$limit = _ref.limit, limit = _ref$limit === void 0 ? 10 : _ref$limit, _ref$approved = _ref.approved, approved = _ref$approved === void 0 ? true : _ref$approved; productReviewService = req.scope.resolve("productReviewService"); _context.next = 6; return productReviewService.getReviews(id, approved === "all" ? approved : approved === "true", parseInt(page), parseInt(limit)); case 6: _yield$productReviewS = _context.sent; reviews = _yield$productReviewS.reviews; total = _yield$productReviewS.total; return _context.abrupt("return", res.json({ reviews: reviews, total: total })); case 12: _context.prev = 12; _context.t0 = _context["catch"](0); console.log(_context.t0); return _context.abrupt("return", res.status(500).json({ message: _context.t0.message })); case 16: case "end": return _context.stop(); } }, _callee, null, [[0, 12]]); })); return _GET.apply(this, arguments); }